﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Model;
using GenericLibrariesToolKit;
using GenericLibrariesToolKit.Enumeration;
using BLL.Users;
using BLL.Users.Impl;
using Utils;
public partial class Page_Security_GetBackPswd : System.Web.UI.Page
{
    //获取当前路径
    string path = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        //
        path = Request.Url.ToString();
        int index = path.IndexOf("WebUI/Page/") + 11;
        path = path.Substring(0, index);
    }
    /// <summary>
    /// 显示安全问题
    /// </summary>
    /// <returns></returns>
    public bool showSecurityQuestion(string userID)
    {
        UserBO userBO = new UserBOImpl();
        
        //执行查询语句
        User user = userBO.Find(userID);
        if (user == null)
            return false;
        //显示安全问题
        txtGetPasswordBackSecurityQuestion.Text = user.SecurityQuestion.ToString();
        return true;
    }

    protected void btnGetPasswordBackSubmit_Click(object sender, ImageClickEventArgs e)
    {
        UserBO userBO = new UserBOImpl();
        //获取数据
        string securityAnswer = txtGetPasswordBackSecurityAnwser.Text.Trim().ToString();
        string userID = txtGetPasswordBackUserName.Text.Trim().ToString();
        //验证安全回答
        User user = userBO.Find(userID);
        if (user.SecurityAnswer==securityAnswer)
        {
            //将用户编号存入Session
            //Session["userId"] = userID;
            Response.Redirect("ResetPasswordaspx.aspx?userId="+userID);
        }
        else
            Response.Write("<script>alert('" + "Answer is wrong" + "')</script>");
    }

    //Back
    protected void btnGetPasswordBackBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("<script language=javascript>history.go(-2);</script>");
    }

    //textChanged事件
    protected void txtGetPasswordBackUserName_TextChanged(object sender, EventArgs e)
    {
        //Response.Write("<script>alert('" + "Answer is wrong" + "')</script>");
        string userID = txtGetPasswordBackUserName.Text.Trim().ToString();
        if (userID == "")
            return;
        showSecurityQuestion(userID);
    }
}